package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.HelpCenter;
import com.sxkf.template.service.HelpCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.util.CheckEmptyUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-12-27 10:17:32
 */
@Api(tags = "帮助中心")
@RestController
@RequestMapping("/helpCenter")
public class HelpCenterController {

    @Resource
    private HelpCenterService helpCenterService;

    @ApiOperation("创建帮助文档")
    @PostMapping("/createHelpCenter")
    public R<Boolean> createHelpCenter(@RequestBody HelpCenter helpCenter) {
        return R.success(helpCenterService.save(helpCenter));
    }

    @ApiOperation("更新帮助文档")
    @PostMapping("/updateHelpCenter")
    public R<Boolean> updateHelpCenter(@RequestBody HelpCenter helpCenter) {
        return R.success(helpCenterService.updateById(helpCenter));
    }

    @ApiOperation("删除帮助文档")
    @PostMapping("/deleteHelpCenter")
    public R<Boolean> deleteHelpCenter(@RequestParam String id) {
        return R.success(helpCenterService.removeById(id));
    }

    @ApiOperation("查询帮助文档")
    @GetMapping("/listHelpCenter")
    public R<List<HelpCenter>> listHelpCenter(@RequestParam(required = false) String pid) {
        return R.success(helpCenterService.list(new LambdaQueryWrapper<HelpCenter>()
                .eq(CheckEmptyUtil.isNotEmpty(pid),HelpCenter::getPid,pid)
                .orderByAsc(HelpCenter::getSort)));
    }
}
